import { createRouter, createWebHashHistory } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

const routes = [
  {
    path: '/',
    name: 'home',
    meta: {
      title: '首页'
    },
    component: () => import(/* webpackChunkName: "index" */ '../views/home/HomeView')
  },
  {
    path: '/programming',
    name: 'home_programming',
    meta: {
      title: '编程'
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    // component: () => import(/* webpackChunkName: "home_programming" */ '../views/programming/ProgrammingView'),
    children: [
      {
        path: '/article/writing',
        name: 'article_writing',
        meta: {
          title: '写文章'
        },
        component: () => import(/* webpackChunkName: "article_writing" */ '../views/programming/article/ArticleWriting')
      },
      {
        path: '/article/list',
        name: 'article_list',
        meta: {
          title: '文章列表'
        },
        component: () => import(/* webpackChunkName: "article_list" */ '../views/programming/article/article-list')
      },
      {
        path: '/article',
        name: 'article',
        meta: {
          title: '文章'
        },
        component: () => import(/* webpackChunkName: "article" */ '../views/programming/article/article-view')
      },
      {
        path: '/article/classification',
        name: 'article_classification',
        meta: {
          title: '文章专栏'
        },
        component: () => import(/* webpackChunkName: "article_classification" */ '../views/programming/article/article-classification')
      }
    ]
  },
  {
    path: '/algorithm',
    name: 'home_algorithm',
    meta: {
      title: '算法'
    },
    // component: () => import(/* webpackChunkName: "home_algorithm" */ '../views/algorithm/AlgorithmView')
    children: [
      {
        path: '/creating',
        name: 'problem_creating',
        meta: {
          title: '创建题目'
        },
        component: () => import(/* webpackChunkName: "problem_creating" */ '../views/algorithm/problem-design/problem-creating/problem-creating')
      },
      {
        path: 'problem/releasing',
        name: 'problem_releasing',
        meta: {
          title: '发布题目'
        },
        component: () => import(/* webpackChunkName: "problem_releasing" */ '../views/algorithm/problem-design/problem-releasing/problem-releasing')
      },
      {
        path: 'problem/draft/list',
        name: 'problem_draft_list',
        meta: {
          title: '题目草稿列表'
        },
        component: () => import(/* webpackChunkName: "problem_releasing" */ '../views/algorithm/problem-design/problem-releasing/problem-releasing')
      },
      {
        path: '/problem/list',
        name: 'problem_list',
        meta: {
          title: '题目列表'
        },
        component: () => import(/* webpackChunkName: problem_list */ '../views/algorithm/problem-list/problem-list')
      },
      {
        path: '/problem/detail',
        name: 'problem_detail',
        meta: {
          title: '题目详情'
        },
        component: () => import(/* webpackChunkName: problem_detail */ '../views/algorithm/problem-detail/problem-detail')
      }
    ]
  },
  {
    path: '/login',
    name: 'user_login',
    meta: {
      title: '登录'
    },
    component: () => import(/* webpackChunkName: "user_login" */ '../views/user/UserLogin')
  },
  {
    path: '/register',
    name: 'user_register',
    meta: {
      title: '用户注册'
    },
    component: () => import(/* webpackChunkName: "user_register" */ '../views/user/UserRegister')
  },
  {
    path: '/password',
    name: 'change_password',
    meta: {
      title: '修改密码'
    },
    component: () => import(/* webpackChunkName: "user_change_password" */ '../views/user/user-change-password')
  },
  {
    path: '/logout',
    name: 'user_logout',
    meta: {
      title: '登出'
    },
    component: () => import(/* webpackChunkName: "user_register" */ '../components/user/UserLogout')
  },
  {
    path: '/permission_control',
    name: 'permission_control',
    meta: {
      title: '权限管理'
    },
    children: [
      {
        path: '/user',
        name: 'permission_user',
        meta: {
          title: '用户管理'
        },
        component: () => import(/* webpackChunkName: "user_permission" */ '../views/permission/user/UserPermissionViews')
      },
      {
        path: '/role',
        name: 'permission_role',
        meta: {
          title: '角色管理'
        },
        component: () => import(/* webpackChunkName: "role_permission" */ '../views/permission/role/RolePermissionViews')
      },
      {
        path: '/permission',
        name: 'permission',
        meta: {
          title: '权限管理'
        },
        component: () => import(/* webpackChunkName: "permission_permission" */ '../views/permission/permission/PermissionViews')
      }
    ]
  },
  {
    path: '/administrator',
    name: 'administrator',
    meta: {
      title: '管理员'
    },
    // component: () => import(/* webpackChunkName: "administrator" */ '../views/administrator')
    children: [
      {
        path: '/management/label',
        name: 'label_management',
        meta: {
          title: '标签页管理'
        },
        component: () => import(/* webpackChunkName: "label_management" */ '../views/administrator/label/label-management')
      },
      {
        path: '/management/classification',
        name: 'classification_management',
        meta: {
          title: '专栏管理'
        },
        component: () => import(/* webpackChunkName: "classification_management" */ '../views/administrator/classification/classification-management')
      },
      {
        path: '/new_registered_user_management',
        name: 'new-registered-user-management',
        meta: {
          title: '新注册用户管理'
        },
        component: () => import(/* webpackChunkName: "classification_management" */ '../views/administrator/new-registered-user-management/new-registered-user-management')
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
const np = NProgress
np.configure({ showSpinner: false })
np.inc()
// np.configure({ easing: 'ease', speed: 500, showSpinner: false })
router.beforeEach(async (to, from, next) => {
  const title = to.meta.title
  if (title) {
    document.title = to.meta.title
  } else {
    document.title = 'learner'
  }
  np.start()
  next()
})
router.afterEach(() => {
  np.done()
})
export default router
